﻿//Write a program that finds the maximal increasing sequence in an array.
//Example: {3, 2, 3, 4, 2, 2, 4} -> {2, 3, 4}.


namespace MaximalIncreasingSequenceOfArray
{
    using System;

    public class MaximalIncreasingSequenceOfArray
    {
        public static void Main(string[] args)
        {            
            Console.Write("Enter array lengh: n = ");
            int arrayElementsCount = int.Parse(Console.ReadLine());
            Console.WriteLine();
            int[] arrayOfElements = new int[arrayElementsCount];
            Console.WriteLine("Enter {0} elements!", arrayElementsCount);
            for (int i = 0; i < arrayOfElements.Length; i++)
            {
                arrayOfElements[i] = int.Parse(Console.ReadLine());                
            }

            Console.WriteLine();
            foreach (int element in arrayOfElements)
            {
                Console.Write(element + " ");
            }

            Console.WriteLine();
            Console.WriteLine();

            int elementCount = 1;
            int elementIndex = 0;
            for (int indexOfElements = 0; indexOfElements < arrayOfElements.Length; indexOfElements++)
            {
                int tempVariable = 1;
                int tempIndex = 0;
                for (int i = indexOfElements + 1; i < arrayOfElements.Length; i++)
                {
                    if ((arrayOfElements[i] - arrayOfElements[i - 1]) == 1)
                    {
                        tempVariable++;
                        tempIndex = i;
                    }
                    else
                    {
                        break;
                    }
                }

                if (elementCount < tempVariable)
                {
                    elementCount = tempVariable;
                    elementIndex = tempIndex;
                }
            }

            Console.WriteLine("Maximal increasing sequence is from {0} elements.", elementCount);
            Console.Write("Appears from index {0} to index {1}  (", elementIndex - elementCount + 2, elementIndex + 1);
            for (int i = elementIndex - elementCount + 1; i <= elementIndex; i++)
            {
                Console.Write(arrayOfElements[i] + " ");
            }

            Console.Write(")");
            Console.WriteLine();
        }
    }
}
